//
// Created by xili on 2024/9/9 16:39.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minimizeArrayValue(vector<int> &nums) {
        int n = nums.size();
        for (int j = 0; j < 2; j++) {
            for (int i = 1; i < n; i++) {
                if (nums[i] > nums[i - 1] + 1) {
                    int t = (nums[i] - nums[i - 1]) >> 1;
                    nums[i] -= t;
                    nums[i - 1] += t;
                }
            }
        }
        return *max_element(nums.begin(), nums.end());
    }
};